追蹤和記錄系統的運行狀態,以便在出現問題或需要故障排除時提供有用的信息。
LOG 檔常用於:
📌 class log
{
public $comment;
public function put_test($data)
{
$this -> comment = $data;
}
public function write()
{
$data = $this -> comment;
$dir = './log/'.$GLOBALS['time'];
$filename = $dir.'.txt';
if($fp = fopen($filename, 'w+'))
{
fwrite($fp, $data);
fclose($fp);
}
}
}
📌 include "./lib/log.php";
$log = new log();
$log → put_test(”test”)
$log → write()
put_test() → 放要寫的內容
write() → 存取在LOG分支
📌 if($fp = fopen($filename, 'w+'))
{
fwrite($fp, $data);
fclose($fp);
}
當你想要驗證程式錯誤
或是寫日誌時,就能用到了~